package chances.webui.taglibs;

import java.util.Objects;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.springframework.util.Assert;

import chances.webui.model.TimelineNode;

@SuppressWarnings("serial")
public class TimelineNodeTag extends BodyTagSupport {
	private TimelineNode timelineNode;

	@Override
	public void setPageContext(PageContext pageContext) {
		super.setPageContext(pageContext);
		timelineNode = new TimelineNode();
	}

	@Override
	public int doEndTag() throws JspException {
		TimelineTag timelineTag = (TimelineTag) findAncestorWithClass(this, TimelineTag.class);
		Assert.notNull(timelineTag);
		if(Objects.nonNull(getLookup())){
			timelineTag.addLookup(getField()+"Lookup", getLookup());
		}
		timelineTag.addTimelineNode(timelineNode);
		return super.doEndTag();
	}

	public String getStyleClass() {
		return timelineNode.getStyleClass();
	}

	public void setStyleClass(String styleClass) {
		timelineNode.setStyleClass(styleClass);
	}

	public String getField() {
		return timelineNode.getField();
	}

	public void setField(String field) {
		timelineNode.setField(field);
	}

	public String getFormat() {
		return timelineNode.getFormat();
	}

	public void setFormat(String format) {
		timelineNode.setFormat(format);
	}

	public Object getLookup() {
		return timelineNode.getLookup();
	}

	public void setLookup(Object lookup) {
		timelineNode.setLookup(lookup);
	}

	public String getStyle() {
		return timelineNode.getStyle();
	}

	public void setStyle(String style) {
		timelineNode.setStyle(style);
	}

	
}
